import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
// 导入路由
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/subCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/CheckOut/index.vue'
import Pay from '@/views/pay/index.vue'
import My from '@/views/My/index.vue'
import MemberInfo from '@/views/My/components/UserInfo.vue'
import MemberOrder from '@/views/My/components/UserOrder.vue'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
   {
    path:'/',
    component:Layout,
    children:[
      {
        path:'',
        component:Home
      },
      {
        path:'/category/:id',
        component:Category
      },
      {
        path:'/category/sub/:id',
        component:SubCategory
      },
      {
        path: 'detail/:id',
        component: Detail
      },
      {
        path:'cartlist',
        component:CartList
      },
      {
        path:'checkout',
        component:Checkout
      },
      {
        path:'pay',
        component:Pay
      },
      {
        path: '/member',
        component: My,
        redirect: '/member/user', 
        children:[
          {
            path:'user',
            component:MemberInfo
          },
          {
            path:'order',
            component:MemberOrder
          }
        ]
      }
    ],
   },
   {
    path:'/login',
    component:Login
   }
  ],
  // 路由行为定制
  scrollBehavior(){
    return {top : 0}
  }       
})

export default router
